{extend name="public:layout" /}
{block name="title"}添加表单{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="alert alert-warning">
        <p>1、PC、手机、各行各业、各种颜色、各种css框架等差异化，无法前端自动化</p>
        <p>2、又不想表单样式单一，只好采取折中处理，前端交由用户制作</p>
        <p>3、这里只是生成了一套参考表单模板，具体模板样式，html代码，js前段验证框架自由发挥</p>
        <p>4、只需要最后把表单数据提交到home/Form/add即可，后端统一验证，验证结果返回用户处理</p>
    </div>
<textarea class="form-control" rows="10">
&lt;form method="post" id="{$formInfo['table_name']}-form"&gt;
    <input type="hidden" name="form_id" value="{$formInfo['form_id']}" />
{volist name="fieldList" id="vo"}
    <div class="{$formInfo['table_name']}-group">
        <label class="{$formInfo['table_name']}-lable">{$vo.field_title}</label>
        <div class="{$formInfo['table_name']}-content">
            {$vo.html}
        </div>
    </div>
{/volist}
{eq name="formInfo.form_code" value="1"}
    <div class="{$formInfo['table_name']}-group">
        <label class="{$formInfo['table_name']}-lable">验证码</label>
        <div class="{$formInfo['table_name']}-content">
            <input name="vcode" placeholder="图形验证码" type="text">
            <img src="{literal}{:captcha_src()}{/literal}" onclick="refreshVerify(this)" alt="刷新验证码">
        </div>
    </div>
{/eq}
    <div class="subBtn">
        <button class="u-btn" type="button" onclick="subForm();">立即提交</button>
        <span class="errMsg"></span>
    </div>
&lt;/form&gt;
    <script type="text/javascript">
        {eq name="formInfo.form_code" value="1"}
        //刷新验证码
        function refreshVerify(obj) {
            var ts = Date.parse(new Date()) / 1000;
            var src = $(obj).attr('src');
            $(obj).attr('src', src+"?id=" + ts);
        }
        {/eq}
        //提交表单
        function subForm() {
            var url = "{literal}{:url('plus/Form/add')}{/literal}";
            var formId = "#{$formInfo['table_name']}-form";
            $.post(url,$(formId).serialize(),function (res) {
                if(res.code==1){
                    //成功后操作
                }else{
                    $('.errMsg').text(res.msg);
                }
            });
        }
    </script>
</textarea>
</div>
{/block}
{block name="script"}{/block}


